class PrivateMessageController < ApplicationController
  def inbox
	user = User.find(session[:user_id])
	@messages = user.private_messages
  end

  def new
	@param1 = params[:param1]
	if params[:private_message]
		user = User.find_by_username(params[:private_message][:name_receiver])
		if user
			private_message = PrivateMessage.new(:subject => params[:private_message][:subject],
												  :message => params[:private_message][:message],
												  :receiver => User.find(session[:user_id]).username,
												  :user_id => user.id)
			if private_message.save
				redirect_to "/private_message/inbox"
			end
		end
	end
  end
  
  def show
	@message = PrivateMessage.find(params[:id])
  end
  
  def delete
	PrivateMessage.find(params[:id]).delete
	redirect_to "/private_message/inbox"
  end
  
end
